//
//  HZRewardDetailHeaderView.m
//  Stock_Stategy
//
//  Created by zeroing on 17/6/5.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZRewardDetailHeaderView.h"

#define kUpDownMargin 5
#define kLeftRightMargin 15

@interface HZRewardDetailHeaderView()
@property (nonatomic, strong)UILabel *pProfitMoneyLabel;
@property (nonatomic, strong)UILabel *pProfitNameLabel;
@property (nonatomic, strong)NSArray *pContentArray;
@property (nonatomic, strong)UIView  *pPreObject;
@end

@implementation HZRewardDetailHeaderView
#pragma mark -
#pragma mark 生命周期
- (instancetype)init{
    self = [super init];
    if (self) {
        [self commonInit];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}
#pragma mark -
#pragma mark private
- (void)commonInit{
    _pProfitMoneyLabel = [UILabel new];
    _pProfitNameLabel = [UILabel new];
    
    _pProfitNameLabel.text = @"浮动盈亏";
    _pProfitMoneyLabel.textAlignment = _pProfitNameLabel.textAlignment = NSTextAlignmentCenter;
    _pProfitMoneyLabel.font = [UIFont boldSystemFontOfSize:25];
    _pProfitNameLabel.font = [UIFont systemFontOfSize:15];
    
    [self addSubview:_pProfitMoneyLabel];
    [self addSubview:_pProfitNameLabel];
    [self p_initConstraints];
    
    NSArray *pTempArray = @[@"成交价",@"股数",@"金额",@"成交时间",@"平仓价",@"股数",@"金额",@"平仓时间"];
    [self p_setDefaultViewWith:pTempArray];
}
- (void)p_initConstraints
{
    [_pProfitMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(kUpDownMargin);
        make.left.right.mas_equalTo(self);
        make.bottom.mas_equalTo(_pProfitNameLabel.mas_top);
        make.height.mas_equalTo(20);
    }];
    [_pProfitNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self);
        make.height.mas_equalTo(_pProfitMoneyLabel);
    }];
}
- (void)p_setDefaultViewWith:(NSArray *)names
{
    _pPreObject = _pProfitNameLabel;
    NSMutableArray *pTempArray = [NSMutableArray arrayWithCapacity:4];
    for (NSString *name in names) {
        UILabel *label = [UILabel new];
        UILabel *content = [UILabel new];
        label.text = name;
        label.textAlignment = NSTextAlignmentLeft;
        content.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont systemFontOfSize:15];
        content.font = [UIFont systemFontOfSize:15];
        content.text = @"--";
        
        [self addSubview:label];
        [self addSubview:content];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_pPreObject.mas_bottom);
            make.left.mas_equalTo(self).offset(kLeftRightMargin);
            make.right.mas_equalTo(content.mas_left);
            make.height.mas_equalTo(30);
        }];
        [content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(label);
            make.right.mas_equalTo(self).offset(-kLeftRightMargin);
            make.width.mas_equalTo(label);
            make.height.mas_equalTo(label);
        }];
        
        _pPreObject = label;
        [pTempArray addObject:content];
    }
    _pContentArray = pTempArray;
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_pPreObject).offset(10);
    }];
}
#pragma mark -
#pragma mark public
- (void)updateNewData:(HZRewardListModel *)data{
    _pProfitMoneyLabel.text = [NSString stringWithFormat:@"%0.2f",[data.model_curPrice floatValue] - [data.model_buyPrice floatValue]];
}
@end
